package com.team.merchant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.team.merchant.domain.dto.MerchantDto;
import com.team.merchant.domain.vo.MerchantDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.team.common.log.annotation.Log;
import com.team.common.log.enums.BusinessType;
import com.team.common.security.annotation.RequiresPermissions;
import com.team.merchant.domain.MerchantInfo;
import com.team.merchant.service.IMerchantInfoService;
import com.team.common.core.web.controller.BaseController;
import com.team.common.core.web.domain.AjaxResult;
import com.team.common.core.utils.poi.ExcelUtil;
import com.team.common.core.web.page.TableDataInfo;

/**
 * 商户信息Controller
 * 
 * @author panyue
 * @date 2025-07-14
 */
@RestController
@RequestMapping("/merchant")
public class MerchantInfoController extends BaseController
{
    @Autowired
    private IMerchantInfoService merchantInfoService;

    /**
     * 查询商户信息列表
     */
    @RequiresPermissions("merchant:merchant:list")
    @GetMapping("/list")
    public TableDataInfo list(MerchantDto merchantDto)
    {
        startPage();
        List<MerchantDetailVo> list = merchantInfoService.selectMerchantInfoList(merchantDto);
        return getDataTable(list);
    }

    /**
     * 导出商户信息列表
     */
    @RequiresPermissions("merchant:merchant:export")
    @Log(title = "商户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantDto merchantDto)
    {
        List<MerchantDetailVo> list = merchantInfoService.selectMerchantInfoList(merchantDto);
        ExcelUtil<MerchantDetailVo> util = new ExcelUtil<MerchantDetailVo>(MerchantDetailVo.class);
        util.exportExcel(response, list, "商户信息数据");
    }

    /**
     * 获取商户信息详细信息
     */
    //@RequiresPermissions("merchant:merchant:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(merchantInfoService.selectMerchantInfoById(id));
    }

    /**
     * 审核商户信息
     */
    @RequiresPermissions("merchant:merchant:edit")
    @Log(title = "商户信息", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/{id}")
    public AjaxResult edit(@PathVariable("id") Long id, @RequestParam Long auditStatusId)
    {
        return toAjax(merchantInfoService.updateMerchantInfo(id,auditStatusId));
    }
}
